package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserApiImpl implements UserApi {
    @Autowired
    private UserMapper userMapper;

    /**
     * 保存用户
     *
     * @param user
     * @return 返回自增长的主键值
     */
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 根据手机号查询
     *
     * @param phone 要查询的手机号码
     * @return 返回查询的用户
     */
    @Override
    public User findByMobile(String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile", phone);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public void updatePhone(User user) {
        userMapper.updateById(user);
    }
}
